// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import Vue from 'vue'
import App from './App'
import router from './router'
import {
	Toast
} from 'vant';

import waterfall from "vue-waterfall2";
Vue.use(waterfall);

// import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
// Vue.use(ElementUI);

// import { HappyScroll } from 'vue-happy-scroll'
// import 'vue-happy-scroll/docs/happy-scroll.css'
// Vue.component('happy-scroll', HappyScroll)

import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)

// axios.interceptors.request.use(
// 	config => {
// 		// if (localStorage.getItem("token") != null) {
// 		//   config.headers["token"] = localStorage.getItem("token");
// 		// }
// 		config.headers["token"] = localStorage.getItem("token");
// 		return config;
// 	},
// 	err => Promise.reject(err)
// );
axios.interceptors.response.use(

	response => {
		if (response.status === 200) {

			if (response.data.msg.code === 50401) {
				let wxUrl = ""
				if (process.env.NODE_ENV === "development") {
					wxUrl = window.location.origin + '/web2/sheyingshi/#/login'
						.replace(/[/]/g, "%2f")
						.replace(/[:]/g, "%3a")
						.replace(/[#]/g, "%23")
						.replace(/[&]/g, "%26")
						.replace(/[=]/g, "%3d");
				}
				if (process.env.NODE_ENV === "test") {
					wxUrl = window.location.origin + '/web2/sheyingshi/#/login'
						.replace(/[/]/g, "%2f")
						.replace(/[:]/g, "%3a")
						.replace(/[#]/g, "%23")
						.replace(/[&]/g, "%26")
						.replace(/[=]/g, "%3d");
				}
				if (process.env.NODE_ENV === "production") {
					wxUrl = window.location.origin + '/web/sheyingshi/#/login'
						.replace(/[/]/g, "%2f")
						.replace(/[:]/g, "%3a")
						.replace(/[#]/g, "%23")
						.replace(/[&]/g, "%26")
						.replace(/[=]/g, "%3d");
				}



				var url =
					"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
					'wx154dd8349a505277' +
					"&redirect_uri=" + wxUrl + //这里放当前页面的地址
					"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";

				window.location.href = url;

			} else {
				return Promise.resolve(response);
			}
		} else {
			return Promise.reject(response);
		}

	},
	error => {
		Toast({
			message: error.response.data.message,
			position: 'bottom',
		});
	}
)


if (process.env.NODE_ENV === "development") {
	Vue.prototype.urls = '/apis'
}
if (process.env.NODE_ENV === "test") {
	Vue.prototype.urls = '/apis'
}
if (process.env.NODE_ENV === "production") {
	Vue.prototype.urls = '/api'
}

Vue.config.productionTip = false

Vue.filter('qu0', (val) => {
	if (!val) {
		return ''
	}
	return val.toFixed(2)
})

/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>'
})
